﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NF_Base;
using System.Runtime.InteropServices;
using NF_Web.Event;

namespace NF_Web
{
    public partial class FrmShow : Form
    {
        public FrmShow()
        {
            InitializeComponent();
        }

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;

        //是否显示最小化
        private bool _IsShowMin;
        public bool IsShowMin
        {
            get { return _IsShowMin; }
            set 
            {
                if (value)
                    pnlMin.Hide();
                _IsShowMin = value; 
            }
        }

        /// <summary>
        /// 重新绘制
        /// </summary>
        private void FrmShow_Paint(object sender, PaintEventArgs e)
        {
            Pen p = new Pen(Color.Gray);
            Graphics gs = e.Graphics;
            gs.DrawRectangle(p, 0, 0, this.Width - 1, this.Height - 1);
        }

        /// <summary>
        /// 鼠标进入关闭按钮
        /// </summary>
        private void pnlClose_MouseEnter(object sender, EventArgs e)
        {
            Panel p = sender as Panel;
            if (p.Tag.ToString() == "关闭")
            {
                p.BackgroundImage = global::NF_Web.Properties.Resources.icon_close_hover;
            }
            else if (p.Tag.ToString() == "最小化")
            {
                p.BackgroundImage = global::NF_Web.Properties.Resources.icon_min_hover;
            }
        }

        /// <summary>
        /// 鼠标离开颜色
        /// </summary>
        private void pnlClose_MouseLeave(object sender, EventArgs e)
        {
            Panel p = sender as Panel;
            if (p.Tag.ToString() == "关闭")
            {
                p.BackgroundImage = global::NF_Web.Properties.Resources.Close_w;
            }
            else if (p.Tag.ToString() == "最小化")
            {
                p.BackgroundImage = global::NF_Web.Properties.Resources.Min_w;
            }
        }

        /// <summary>
        /// 关闭
        /// </summary>
        private void pnlClose_MouseClick(object sender, MouseEventArgs e)
        {
            this.Close();
        }



        /// <summary>
        /// 移动事件
        /// </summary>
        private void pnlTop_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
        }


        /// <summary>
        /// 最小化
        /// </summary>
        private void pnlMin_Click(object sender, EventArgs e)
        {
            ActiveEvent.MinForm();
            this.Hide();
        }




    }
}
 